<template>
	<view>
		<keep-alive>
			<view v-if="tabBarIndex == 0">
				<pages-index></pages-index>
			</view>
			<view v-if="tabBarIndex == 1">
				<landlord-message ref="messageRef"></landlord-message>
			</view>
			<view v-if="tabBarIndex == 2">
				<posting @changeIndex="changeIndex" @changeTabbars="changeTabbars"></posting>
			</view>
			<view v-if="tabBarIndex == 3">
				<landlord-manage ref="childRef"></landlord-manage>
			</view>
			<view v-if="tabBarIndex == 4">
				<landlord-index @toFather="toFather" :user="userinfo" ref="childRefindex"></landlord-index>
			</view>
		</keep-alive>
		<landlord-tabbar :unreadNum="unreadNum" :tabBarIndex="tabBarIndex2"
			@changeTabbar="changeTabbar"></landlord-tabbar>
	</view>
</template>

<script>
// import landlordIndex from './components/landlord-index.vue'
// import landlordMessage from './components/landlord-message.vue'
// import landlordManage from './components/landlord-manage.vue'
// import landlordTabbar from './components/landlord-navbar.vue'
import posting from "./landlord/buildings.vue";
import pagesIndex from "./components/index.vue";
export default {
	components: {
		// 	landlordIndex,
		// 	landlordMessage,
		// 	landlordManage,
		// 	landlordTabbar
		posting,
		pagesIndex,
	},
	data() {
		return {
			unreadNum: 0,
			userinfo: {},
			tabBarIndex: "",
			tabBarIndex2: "",
		};
	},

	onLoad(options) {
		console.log(options)
		if (options && options.tabBarIndex) {
			this.tabBarIndex = options.tabBarIndex
			this.tabBarIndex2 = options.tabBarIndex
		} else {
			this.tabBarIndex = 4
			this.tabBarIndex2 = 4
		}
		if (uni.getStorageSync("userInfo")) {
			this.userinfo = uni.getStorageSync("userInfo");
		}
	},
	onShow(e) {
		this.showclick();
		this.$Api.chat.getOwnerUnReadNumber().then(res => {
			console.log("landlord tabbar unread", res.data.data);
			this.unreadNum = res.data.data
		})
		// this.childRefindexlist();
	},
	methods: {
		changeTabbars(data) {
			this.tabBarIndex2 = data;
		},
		changeIndex(data) {
			this.tabBarIndex = data;
		},
		toFather() {
			this.tabBarIndex = 1;
		},
		childRefindexlist() {
			this.$refs.childRefindex.constinit();
		},
		// 子组件事件
		showclick() {
			if (this.tabBarIndex == 1 && this.$refs.messageRef) {
				this.$refs.messageRef.init()
			} else if (this.tabBarIndex == 3 && this.$refs.childRef) {
				this.$refs.childRef.init();
			}
		},
		changeTabbar(index) {
			this.tabBarIndex = index;
			this.tabBarIndex2 = index;
			this.$Api.chat.getOwnerUnReadNumber().then(res => {
				console.log("landlord tabbar unread", res.data.data);
				this.unreadNum = res.data.data
			})
			this.showclick()
		},
	},
};
</script>

<style lang="scss"></style>